package com.example.service;

import cn.hutool.core.date.DateUtil;
import com.example.entity.Account;
import com.example.entity.Dingdanshenhe;
import com.example.mapper.DingdanshenheMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DingdanshenheService {
    @Resource
    DingdanshenheMapper dingdanshenheMapper;
    public void  add(Dingdanshenhe dingdanshenhe) {
        Account accountUser = TokenUtils.getCurrentUser();
        dingdanshenhe.setShangchuanshijian(DateUtil.now());
        dingdanshenhe.setUserId(accountUser.getId());
        dingdanshenhe.setUserName(accountUser.getName());
        dingdanshenhe.setShenhezhuangtai("待发货");
        dingdanshenheMapper.insert(dingdanshenhe);
    }

    public void delete(Integer id) {
        dingdanshenheMapper.deleteById(id);
    }

    public void update(Dingdanshenhe dingdanshenhe) {
        dingdanshenheMapper.updateById(dingdanshenhe);
    }

    public List<Dingdanshenhe> selectAll(Dingdanshenhe dingdanshenhe) {
      return  dingdanshenheMapper.selectAll(dingdanshenhe);
    }

    public PageInfo<Dingdanshenhe> selectPage(Integer pageNum, Integer pageSize, Dingdanshenhe dingdanshenhe) {
        PageHelper.startPage(pageNum, pageSize);
        List<Dingdanshenhe> list = dingdanshenheMapper.selectAll(dingdanshenhe);
        return PageInfo.of(list);
    }
}
